<template>
	<view class="container">
		<view class="cu-bar bg-gradual-blue search">
			<view class="cu-avatar round" style="background-image:url(https://ossweb-img.qq.com/images/lol/web201310/skin/big114004.jpg);"></view>
			<view class="search-form radius">
				<text class="cuIcon-search"></text>
				<input @focus="InputFocus" @blur="InputBlur" :adjust-position="false" type="text" placeholder="搜索图片、文章、视频"
				 confirm-type="search"></input>
			</view>
			<view class="action">
				<text>广州</text>
				<text class="cuIcon-triangledownfill"></text>
			</view>
		</view>

		<HMfilterDropdown :filterData="filterData" :defaultSelected="filterDropdownValue" :updateMenuName="true" @confirm="confirm"
		 dataFormat="Object"></HMfilterDropdown>
		
		<list :listArr="listArr" @onTap="goSecondIndex" />
		<view>
			<view class="index" v-for="(v,index) in indexArr" :key="index">
				<text class="item">{{index}}</text>:{{v|outData}}
			</view>
		</view>
		<view>
			<view class="text">菜单数据value：</view>
			<view class="value" v-for="(v,index) in valueArr" :key="index">
				<text class="item">{{index}}</text>:{{v|outData}}
			</view>
		</view>
	</view>
</template>

<script>
	import interactive from "@/components/interactive.vue";
	import list from "@/components/list.vue";
	import HMfilterDropdown from "@/components/HM-filterDropdown/HM-filterDropdown.vue";

	import {
		mapState
	} from 'vuex';

	export default {
		data() {
			return {
				indexArr: '',
				valueArr: '',
				filterData : [
					{
						"name": '单选',
						"type": 'radio',
						"submenu": [
							{
								"name": "优惠(单选)",
								"submenu": []
							}
						]
					}
				],
				latitude: null,
				longitude: null,
				listArr:[],
			}
		},
		filters: {
			outData(value) {
				return JSON.stringify(value);
			}
		},
		mounted() {
			this.getLocations();
			this.getTypeClass();
		},
		computed: {
			...mapState(['openid', 'typeid'])
		},
		onLoad() {
		},
		methods: {
			goSecondIndex: function(id){
				uni.navigateTo({
					url: `../secondStation/secondStation?id=${id}`
				})
			},
			
			/* 
				获得公司信息
			 */
			getCompany: function() {
				uni.request({
					url: 'https://wechat.lccmart.com/ygy/api/wechatapi/get_customer',
					method: 'POST',
					data: {
						openid: this.openid,
						type: this.typeid,
						longitude: this.longitude,
						latitude: this.latitude
					},
					success: (res) => {
						const data = res.data.data;
						this.listArr = data;
						console.log(data)
					}
				})
			},
			/* 
				获取用户地理位置
			 */
			getLocations: function() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						this.latitude = res.latitude;
						this.longitude = res.longitude;
						this.getCompany();
					}
				})
			},
			/* 
				获得分类信息
			 */
			getTypeClass: function() {
				uni.request({
					url: 'https://wechat.lccmart.com/ygy/api/wechatapi/get_type',
					method: 'POST',
					success: (res) => {
						let data = res.data.data;
						let newArr = [];
						data.forEach((el, index) => {
							let arr = JSON.parse(JSON.stringify(el).replace(/id/g, 'value'))
							newArr.push(arr)
						})
						this.filterData[0].submenu[0].submenu = newArr;
					}
				})
			},
			chooseCity() {
				uni.navigateTo({
					url: "../chooseCity/chooseCity"
				})
			},
			/* 
				接收筛选结果
			 */
			confirm(e) {
				this.indexArr = e.index;
				this.valueArr = e.value;
				return;
				console.log('修改菜单');
				this.filterData[4].submenu[1] = {
					"name": "项目2",
					"submenu": [

					]
				}
			}
		},
		components: {
			interactive,
			list,
			HMfilterDropdown
		}
	}
</script>

<style lang="less" scoped>
	.top_content {
		display: flex;
		width: 100%;
		height: 120rpx;
		border-bottom: 1px solid #ccc;
		background-color: #fff;

		.left {
			width: 25%;
			height: 120rpx;
			line-height: 120rpx;
			padding-left: 40rpx;
			box-sizing: border-box;
		}

		.right {
			display: flex;
			align-items: center;
			width: 75%;
			padding-right: 16rpx;
			box-sizing: border-box;

			.input {
				width: 65%;
				height: 38px;
				border: 1px solid #ccc;
				border-radius: 10rpx;
				padding-left: 10rpx;
				box-shadow: border-box;
			}

			.button {
				width: 30%;
			}
		}
	}

	.list_content {
		padding: 0 20rpx;
	}
</style>
